package com.caltco.cargo.ops.modules.sys.controller;

import com.caltco.cargo.ops.common.api.R2;
import com.caltco.cargo.ops.common.api.Result;
import com.caltco.cargo.ops.modules.sys.request.SaveLearnBookRequest;
import com.caltco.cargo.ops.modules.sys.service.WordService;
import com.caltco.cargo.ops.modules.sys.vo.LearnBookVO;
import com.caltco.cargo.ops.modules.sys.vo.WordVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/word")
public class WordController {
    private final WordService wordService;

    public WordController(WordService wordService) {
        this.wordService = wordService;
    }

    @GetMapping("get")
    public Result<WordVO> getWordByType(@RequestParam("type") String type) {
        return R2.ok(wordService.getWordByType(type));
    }

    @GetMapping("getByRandom")
    public Result<WordVO> getWordByType() {
        return R2.ok(wordService.getByRandom());
    }

    @GetMapping("getWordByTest")
    public Result<WordVO> getWordByTest() {
        return R2.ok(wordService.getWordByTest());
    }

    @GetMapping("getWordByEnter")
    public Result<WordVO> getWordByEnter() {
        return R2.ok(wordService.getWordByEnter());
    }

    @GetMapping("getLearnBook")
    public Result<List<LearnBookVO>> getLearnBook() {
        return R2.ok(wordService.getLearnBook());
    }

    @GetMapping("getAllLearnBook")
    public Result<List<LearnBookVO>> getAllLearnBook() {
        return R2.ok(wordService.getAllLearnBook());
    }

    @DeleteMapping("removeLearnBook")
    public Result<String> removeLearnBook(@RequestBody SaveLearnBookRequest request) {
        return wordService.removeLearnBook(request)?R2.ok("移除成功"):R2.err("移除失败");
    }


    @PostMapping("saveLearnBook")
    public Result<String> saveLearnBook(@RequestBody SaveLearnBookRequest request) {
        return wordService.saveLearnBook(request) ? R2.ok("添加成功") : R2.err("添加失败");
    }


}
